package com.topboya.linker.ui.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.model.levelitem.DepartmentGroupBo;
import com.topboya.linker.utils.LogUtils;

import java.util.List;

import retrofit2.http.POST;

//自己写的adapter在返回的时候数据老有问题，后面在研究一下
public class SelecVistorLeftAdapter extends RecyclerView.Adapter<SelecVistorLeftAdapter.ListItemViewHolder> {

    private static final String TAG = "SelecVistorLeftAdapter:";
    private List<String> departmetname;
    private int currentPosition;
    public SelecVistorLeftAdapter(List<String> departmetname) {

        this.departmetname = departmetname;

    }

    @Override
    public ListItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.select_vistor_item_left, viewGroup, false);
        return new ListItemViewHolder(itemView);

    }


    //绑定界面，设置监听
    @Override
    public void onBindViewHolder(final ListItemViewHolder holder, final int position) {

        LogUtils.v(TAG+"departmetGroupList---:"+departmetname.toString());

         holder.tv_departname.setText(departmetname.get(position));
        if (position == currentPosition) {

            holder.tv_departname.setBackgroundResource(R.drawable.selector_vistor_left);
            holder.tv_departname.setTextColor(Color.WHITE);
        } else {
            holder.tv_departname.setBackgroundColor(Color.WHITE);
            holder.tv_departname.setTextColor(Color.GRAY);
        }
        //点击事件监听
        clickListenter(holder, position);

    }

    private void clickListenter(ListItemViewHolder holder, int i) {
        holder.itemView.setOnClickListener(v -> {

            if (null !=itemClickListener){
                itemClickListener.onClick(holder.itemView,i);
            }
        });

    }

    @Override
    public int getItemCount() {

        return departmetname == null ? 0 : departmetname.size();
    }

    /**
     * 这个方法是用来设置背景的
     *
     * @param position
     */
    public void updateData(int position) {

        currentPosition = position;
        notifyDataSetChanged();
    }
    public class ListItemViewHolder extends RecyclerView.ViewHolder{

        //ViewHolder
        TextView tv_departname;

        ListItemViewHolder(View view) {

            super(view);
            this.tv_departname = view.findViewById(R.id.tv_departname);

        }

    }

    private OnItemClickListener itemClickListener;

    public void setOnItemClickListener(SelecVistorLeftAdapter.OnItemClickListener itemClickListener){

        this.itemClickListener = itemClickListener;
    }

    public interface  OnItemClickListener{

        void onClick(View v, int position);
    }


}
